/*
  Copyright 1996-2003
  Simon Whiteside

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

  $Id: Utils.java,v 1.6 2003/03/20 16:07:03 simkin_cvs Exp $
*/
package simkin;

/**
 * This class provides useful functions to the Simkin library
 */
public final class Utils {
    /**
     * Adds two strings together efficiently
     */
    static public String addStrings(String one,String two){
	StringBuffer buffer=new StringBuffer(one.length()+two.length());
	buffer.append(one);
	buffer.append(two);
	return buffer.toString();
    }
    /**
     * Adds three strings together efficiently
     */
    static public String addStrings(String one,String two,String three){
	StringBuffer buffer=new StringBuffer(one.length()+two.length()+three.length());
	buffer.append(one);
	buffer.append(two);
	buffer.append(three);
	return buffer.toString();
    }
    /**
     * Adds four strings together efficiently
     */
    static public String addStrings(String one,String two,String three,String four){
	StringBuffer buffer=new StringBuffer(one.length()+two.length()+three.length()+four.length());
	buffer.append(one);
	buffer.append(two);
	buffer.append(three);
	buffer.append(four);
	return buffer.toString();
    }
    /**
     * Adds five strings together efficiently
     */
    static public String addStrings(String one,String two,String three,String four,String five){
	StringBuffer buffer=new StringBuffer(one.length()+two.length()+three.length()+four.length()+five.length());
	buffer.append(one);
	buffer.append(two);
	buffer.append(three);
	buffer.append(four);
	buffer.append(five);
	return buffer.toString();
    }
    /**
     * Adds six strings together efficiently
     */
    static public String addStrings(String one,String two,String three,String four,String five,String six){
	StringBuffer buffer=new StringBuffer(one.length()+two.length()+three.length()+four.length()+five.length()+six.length());
	buffer.append(one);
	buffer.append(two);
	buffer.append(three);
	buffer.append(four);
	buffer.append(five);
	buffer.append(six);
	return buffer.toString();
    }
    /**
     * Adds seven strings together efficiently
     */
    static public String addStrings(String one,String two,String three,String four,String five,String six,String seven){
	StringBuffer buffer=new StringBuffer(one.length()+two.length()+three.length()+four.length()+five.length()+six.length()+seven.length());
	buffer.append(one);
	buffer.append(two);
	buffer.append(three);
	buffer.append(four);
	buffer.append(five);
	buffer.append(six);
	buffer.append(seven);
	return buffer.toString();
    }
    /**
     * Adds eight strings together efficiently
     */
    static public String addStrings(String one,String two,String three,String four,String five,String six,String seven,String eight){
	StringBuffer buffer=new StringBuffer(one.length()+two.length()+three.length()+four.length()+five.length()+six.length()+seven.length()+eight.length());
	buffer.append(one);
	buffer.append(two);
	buffer.append(three);
	buffer.append(four);
	buffer.append(five);
	buffer.append(six);
	buffer.append(seven);
	buffer.append(eight);
	return buffer.toString();
    }
    /**
     * This method removes any initial blank lines from the given string. This is useful for trimming the beginning of methods in 
     * Simkin scripts.
     */
    static public String removeInitialBlankLines(String s){
	boolean loop=true;
	while (loop){
	    int cr_pos=s.indexOf('\n');
	    if (cr_pos!=-1){
		String line=s.substring(0,cr_pos);
		if (line.trim().length()==0){
		    s=s.substring(cr_pos+1);
		}else
		    loop=false;
	    }else
		loop=false;
	}
	return s;
    }
}
